package me.jessyan.retrofiturlmanager.manager.view;

import me.jessyan.retrofiturlmanager.manager.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;


/**
 *  WaitingDialogView
 *
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
public class WaitingDialogView {
    private static CommonDialog dialog;
    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;

    public static void show(final Context context, String msg) {
        LayoutScatter scatter = LayoutScatter.getInstance(context);
        Component v = scatter.parse(ResourceTable.Layout_dialog_loading, null, false);
        v.setComponentSize(WIDTH, HEIGHT);
        Text tips = (Text) v.findComponentById(ResourceTable.Id_tv_tips);
        tips.setText(msg);
        dialog = new CommonDialog(context);
        dialog.setSize(v.getWidth(), v.getHeight());
        dialog.setContentCustomComponent(v);
        dialog.show();
    }

    public static void hide() {
        if (dialog != null && dialog.isShowing()) {
            dialog.destroy();
        }
    }
}